package com.annotation.validator;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexFieldValidator extends FieldValidatorSupport{

	private String expression;
	public String getExpression() {
		return expression;
	}
	public void setExpression(String expression) {
		this.expression = expression;
	}

	@Override
	public void validate() {
		Pattern PATTERN=Pattern
		.compile(expression);
		String value=getFieldValue();
		Matcher m = PATTERN.matcher(value);
		if (!m.matches()) {
			addErrorCode(this.getFieldName(),this.getMessage());
		}
		
	}

}
